/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.uet.questiondetector.patterns;

import java.util.ArrayList;

/**
 *
 * @author thinhnk
 */
public class LHS extends ArrayList<String>{
    //Check if a LHS contains another LHS
    public boolean contains(LHS sub, int thres){
        int l1 = this.size();
        int l2 = sub.size();
        if(l1 < l2) return false;
        else{
            int[][] c = new int[l2][l1];
            for(int i = 0; i < l2; i++){
                if(i == 0){
                    for(int j = 0; j < l1; j++){
                        if(sub.get(i).equalsIgnoreCase(this.get(j))){
                            for(int k = j; k < j+thres; k++){
                                if(k == l1) break;
                                else c[i][k] = 1; 
                            }
                        }
                    }
                }
                else{
                    for(int j = 0; j < this.size(); j++){
                        if(sub.get(i).equalsIgnoreCase(this.get(j)) && c[i-1][j] == 1){
                            for(int k = j; k < j+thres; k++){
                                if(k == l1) break;
                                else c[i][k] = 1; 
                            }
                        }
                    }
                }
            }
            for(int t = 0; t < l1; t++){
                if(c[l2-1][t] == 1)
                    return true;
            }
            return false;
        }
    }
    
    @Override
    public String toString(){
        String lhsString = "";
        for(int i = 0; i < this.size(); i++){
            lhsString = lhsString + this.get(i) + " ";
        }
        return lhsString;
    }
}
